<template>
  <div id="app">
    <div class="wrapper">

    <header class="login-header">
      <div class="commonwidth">
        <h1 class="logo">
          <a href="#/">小兔鲜</a>
        </h1>
        <h3 class="sub">欢迎登录</h3>
        <a href="#/" class="entry">
          进入网站首页
          <i class="iconfont icon-angle-right"></i
          ><i class="iconfont icon-angle-right"></i
        ></a>
      </div>
    </header>
    <section class="login-section">
      <div class="wrapper">
        <nav>
          <a href="javascript:;">账户登录</a><a href="javascript:;">扫码登录</a>
        </nav>
        <div class="account-box">
          <div class="toggle">
            <a href="javascript:;"
              ><i class="iconfont icon-envelope-o"></i>
              使用短信登录
              
            </a>
          </div>
          <form novalidate="novalidate" autocomplete="off" class="form">
            <div class="form-item">
              <div class="input">
                <i class="iconfont icon-user-o"></i
                ><input
                  type="text"
                  placeholder="请输入用户名"
                  name="account"
                  @focus="user"
                  @blur="userB"
                  v-model="userVal"
                  :class="{ focus: userBool, cuowu: cuowu }"
                />
              </div>
              <div class="userName" v-show="userName">请输入用户名</div>
              <div class="zf" v-show="zf">字母开头且6-20个字符</div>
              <!---->
            </div>
            <div class="form-item">
              <div class="input">
                <i class="iconfont icon-lock8"></i
                ><input
                  type="password"
                  placeholder="请输入密码"
                  name="password"
                  @focus="pass"
                  @blur="passB"
                  v-model="passVal"
                  :class="{ focus: passBool, passcuowu: passcuowu }"
                />
              </div>
              <div class="userName" v-show="word">请输入密码</div>
              <div class="zf" v-show="zfp">密码6-24个字符</div>
          
            </div>
            <div class="form-item">
              <div class="agree">

                <span>我已同意</span><a href="javascript:;">《隐私条款》</a
                ><span>和</span><a href="javascript:;">《服务条款》</a>
              </div>
            </div>
            <a href="javascript:;" class="btn" @click="login">登录</a>
          </form>
          <div class="action">
            <a
              href="https://graph.qq.com/oauth2.0/authorize?client_id=101941968&amp;response_type=token&amp;scope=all&amp;redirect_uri=http%3A%2F%2Ferabbit.itheima.net%2F%23%2Flogin%2Fcallback"
              ><img
                src="https://qzonestyle.gtimg.cn/qzone/vas/opensns/res/img/Connect_logo_7.png"
                alt=""
            /></a>
            <div class="url">
              <a href="javascript:;">忘记密码</a
              ><a href="javascript:;">免费注册</a>
            </div>
          </div>
        </div>
      </div>
    </section>
    <footer class="login-footer">
      <div class="commonwidth">
        <p>
          <a href="javascript:;">关于我们</a><a href="javascript:;">帮助中心</a
          ><a href="javascript:;">售后服务</a
          ><a href="javascript:;">配送与验收</a
          ><a href="javascript:;">商务合作</a><a href="javascript:;">搜索推荐</a
          ><a href="javascript:;">友情链接</a>
        </p>
        <p>CopyRight © 小兔鲜儿</p>
      </div>
      
    </footer>
    </div>

  </div>
</template>
  <script>
  import axios from 'axios'
export default {
  data() {
    return {
      passVal: "",
      userVal: "",
      userBool: false,
      passBool: false,
      zf: false,
      userName: false,
      cuowu: false,
      passcuowu: false,
      word: false,
      zfp: false,
    };
  },
  methods: {
    user() {
      this.userBool = true;
      this.zf = false;
      this.userName = false;
    },
    pass() {
      this.passBool = true;
      this.zfp = false;
      this.word = false;
    },
    userB() {
      this.userBool = false;
      console.log(this.userVal.length);

      if (this.userVal == "") {
        this.userName = true;
        this.cuowu = true;
        this.zf = false;
      } else {
        this.userName = false;
        if (
          this.userVal.length < 6 ||
          (this.userVal.length > 20 &&
            this.userVal.charCodeAt(0) < 97 &&
            this.userVal.charCodeAt(0) < 101)
        ) {
          this.zf = true;
          this.cuowu = true;
        } else {
          this.zf = false;
          this.cuowu = false;
        }
      }
    },
    passB() {
      this.passBool = false;
      if (this.passVal == "") {
        this.word = true;
        this.passcuowu = true;
        this.zfp = false;
      } else {
        this.word = false;
        if (this.passVal.length < 6 || this.passVal.length > 24) {
          this.zfp = true;
        } else {
          this.zfp = false;
          this.word = false;
        }
      }
    },
    login() {
      var _this = this;

      axios({
        url: "http://pcapi-xiaotuxian-front-devtest.itheima.net/login",
        method: "post",
        data: {
          account: this.userVal,
          password: this.passVal,
        },
      })
        .then(function (res) {
          if (res.data.msg == "操作成功") {
            localStorage.account = res.data.result.account
            localStorage.token =  res.data.result.token
            console.log(res.data.result.token);
            _this.$store.commit('setAccount',res.data.result.account)
            _this.$store.commit('setToken',res.data.result.token)

            console.log(_this.$store.state.user.token);            

            
            alert("登录成功");
            _this.$router.push({ path: "/home" });
          }
        })
        .catch(function (error) {
          console.log(error);
          alert(error.response.data.message);
        });
    },
  },
};
</script>
  <style scoped>
.blur {
  border: 1px solid #cfcdcd;
}
.cuowu {
  border: 1px solid red !important ;
}
.passcuowu {
  border: 1px solid red !important ;
}
.focus {
  border: 1px solid green !important;
}

.login-header {
  background: #fff;
  border-bottom: 1px solid #e4e4e4;
}
.login-header .commonwidth {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}
.login-header .logo {
  width: 200px;
}
.login-header .logo a {
  display: block;
  height: 132px;
  width: 100%;
  text-indent: -9999px;
  background: url("http://erabbit.itheima.net/img/logo.0940ebb5.png") no-repeat
    center 18px / contain;
}
.login-header .sub {
  flex: 1;
  font-size: 24px;
  font-weight: 400;
  margin-bottom: 38px;
  margin-left: 20px;
  color: #666;
}
.login-header .entry {
  width: 120px;
  margin-bottom: 38px;
  font-size: 16px;
}
.login-header .entry i {
  font-size: 14px;
  color: #27ba9b;
  letter-spacing: -5px;
}
.login-section {
  background: url("http://erabbit.itheima.net/img/login-bg.696efec3.png")
    no-repeat 50% / cover;
  height: 488px;
  position: relative;
}
.login-section .wrapper {
  width: 380px;
  background: #fff;
  min-height: 400px;
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translate3d(100px, 0, 0);
  box-shadow: 0 0 10px rgb(0 0 0 / 15%);
}
.login-section .wrapper nav {
  height: 55px;
  border-bottom: 1px solid #f5f5f5;
  display: flex;
  padding: 0 40px;
  text-align: right;
  align-items: center;
}
.login-section .wrapper nav a:first-child {
  border-right: 1px solid #f5f5f5;
  text-align: left;
}
.login-section .wrapper nav a {
  flex: 1;
  line-height: 1;
  display: inline-block;
  font-size: 18px;
  position: relative;
}
.account-box .toggle {
  padding: 15px 40px;
  text-align: right;
}
.account-box .toggle a {
  color: #27ba9b;
}
.account-box .toggle a i {
  font-size: 14px;
}
.account-box .form {
  padding: 0 40px;
}
.account-box .form-item {
  margin-bottom: 28px;
  position: relative;
}
.account-box .form-item .input {
  position: relative;
  height: 36px;
}
.account-box .form-item .input > i {
  width: 34px;
  height: 34px;
  background: #cfcdcd;
  color: #fff;
  position: absolute;
  left: 1px;
  top: 1px;
  text-align: center;
  line-height: 34px;
  font-size: 18px;
}
.account-box .form-item .input input {
  padding-left: 44px;
  border: 1px solid #cfcdcd;
  height: 36px;
  line-height: 36px;
  width: 80%;
}
.account-box .form-item {
  margin-bottom: 28px;
}
.account-box .form-item .input > i {
  width: 34px;
  height: 34px;
  background: #cfcdcd;
  color: #fff;
  position: absolute;
  left: 1px;
  top: 1px;
  text-align: center;
  line-height: 34px;
  font-size: 18px;
}
.account-box .form .btn {
  display: block;
  width: 100%;
  height: 40px;
  color: #fff;
  text-align: center;
  line-height: 40px;
  background: #27ba9b;
}
.account-box .action {
  padding: 20px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.account-box .action .url a {
  color: #999;
  margin-left: 10px;
}
.login-footer {
  padding: 30px 0 50px;
  background: #fff;
}
.login-footer p {
  text-align: center;
  color: #999;
  padding-top: 20px;
}
.login-footer p a {
  line-height: 1;
  padding: 0 10px;
  color: #999;
  display: inline-block;
}
.userName,
.zf {
  color: red;
  font-size: 12px;
  position: absolute;
  top: 40px;
}

.form-item{
  text-align: left;
}
</style>